﻿
var  strUrlHost="http://211.140.17.102:7080/monitor/service";
function addMethod(method){
	strUrlHost=strUrlHost+"?method="+method;
}
function addToken(){
	var token= window.localStorage.getItem("accessToken");	
	strUrlHost=strUrlHost+"&access_token="+token;
}
function addPassword(oldPassword,newPassword){
	strUrlHost=strUrlHost+"&password="+oldPassword+"&newpassword="+newPassword;
}

function conbineRequestUrl(method, oldPassword,newPassword){
	addMethod(method);
	addToken();
	addPassword(oldPassword,newPassword);
	return strUrlHost;
}

function onModifiedPassword(){	
	var oldPassword= document.getElementById("id-old-password").value;
	var  newPassword= document.getElementById("id-new-password").value;	
	var  confirmPassword= document.getElementById("id-confirm-password").value;	
	var pattern = /^[0-9a-zA-Z!&*^%$#@~|]{6,20}$/;	
	if(!pattern.test(oldPassword)){
		showToast("原始密码格式错误");		
		return;
	}
	if(!pattern.test(newPassword)){
		showToast("新密码格式错误");
		return;
	}	
	if(!pattern.test(confirmPassword)){
		showToast("确认密码格式错误");
		return;
	}	
	if(oldPassword==newPassword){
		showToast("新密码与老密码相同");
		return;
	}	
	if(newPassword!=confirmPassword){
		showToast("新密码与老密码不相同");
		return;
	}
	var strRequestUrl= conbineRequestUrl("modifypasswd",oldPassword,newPassword);
	console.log("strRequestUrl="+strRequestUrl);
	$.ajax({
		type:"post",
		url:strRequestUrl,
		success:function(resultData){
			var flag=resultData.success;
			var code=resultData.errorcode;
			//alert("flag="+flag+",code="+code);
			console.log("flag="+flag+",code="+code);
		}
		
	});
}

function showToast(message){
	document.getElementById("id-toast").style.display='block'; 
	document.getElementById("id-toast").style.opacity=1;         
	var msg='<div style="color:#fff;background: rgba(0, 0, 0, 0.6);border-radius: 2px;padding: 2px;text-align: center;width:175px;margin: 0 auto;">'+message+'</div>';
	document.getElementById("id-toast").innerHTML=msg;
	setTimeout(function(){
		document.getElementById("id-toast").style.opacity=0;
		setTimeout(function(){
					document.getElementById("id-toast").style.display='none';
		     }, 1000)
	},1000);
}

